<?php
require_once dirname(__FILE__).'/../../bootstrap/unit.php';

class unit_SimpleMessageWorkflowTest extends sfPHPUnitBaseTestCase
{
  
  public function testScenario ()
  {
    $num_workflow_instances_before = wfWorkflowInstanceTable::getInstance()->count();
    $num_work_items_before = count(wfWorkflowWorkItemTable::getInstance()->findAll());
    
    $recipients = sfGuarduserTable::getInstance()->findAll();
    $recipient_user_ids = array();
    foreach ($recipients as $recipient)
    {
      $recipient_user_ids[] = $recipient->getId();
    }
    
    $workflow = new SimpleMessageWorkflow('test-subject', 'test-message', $recipient_user_ids);
    $workflow->start();
    
    $new_work_items = 0;
    //$new_work_items += 1; // Split
    $new_work_items += count($recipient_user_ids); // Message steps
    

    $num_workflow_instances_after = wfWorkflowInstanceTable::getInstance()->count();
    $num_work_items_after = count(wfWorkflowWorkItemTable::getInstance()->findAll());
    
    $this->assertEquals($num_workflow_instances_before + 1, $num_workflow_instances_after);
    $this->assertEquals($num_work_items_before + $new_work_items, $num_work_items_after);
    
    $this->assertTrue($workflow->getObject()->isCompleted());
  }
}